package com.gm.corejava.book2;

import javax.swing.table.AbstractTableModel;
import java.awt.*;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-12-26
 * Time: 上午10:20
 * To change this template use File | Settings | File Templates.
 */
public class PanetTableModel extends AbstractTableModel {
    @Override
    public int getRowCount() {
        return cells.length;
    }

    @Override
    public int getColumnCount() {
       return columnNames.length;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return cells[0][columnIndex].getClass();
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        cells[rowIndex][columnIndex]=aValue;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
       return columnIndex==PLANT_COLUMN || columnIndex==MOON_COLUMN || columnIndex==GASEOUT_COLUMN || columnIndex==COLOR_COLUMN;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return cells[rowIndex][columnIndex];
    }

    @Override
    public String getColumnName(int column) {
        return columnNames[column];
    }

    private Object[][] cells={
            {"Mercury",2440,0,false, Color.YELLOW},
            {"Venus",6052,0,false, Color.YELLOW},
            {"Earth",6378,1,false, Color.BLUE},

    };

    public final static int PLANT_COLUMN=0;
    public  final static int MOON_COLUMN=2;
    public final static int GASEOUT_COLUMN=3;
    public  final static int COLOR_COLUMN=4;
    private String[] columnNames={"Planet","Radius","Moons","Gaseous","Color"};
}
